<?php

use yii\helpers\Html;
use yii\widgets\LinkPager;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '关于【' . $name . '】最新技术文章、讲义下载、活动 - ' . Yii::$app->params['site_name'];
$title = $name . " 话题";
$this->params['breadcrumbs'][] = $title;
?>
<div class="download-index row">

    <div class="col-md-9">
        <h1>关于#<?= Html::encode($name) ?>#的话题</h1>
        <h3 class="sky"><a href="/<?= $slug; ?>/manuals"><i class="iconfont">&#xe602;</i>入门 · 手册</a></h3><p>&nbsp;</p>
        <?php
        if (!empty($manuals)) {
            foreach ($manuals as $value) {
//                $date = date("Y-m-d H:i:s", $value['created_at']);
                echo "<div class='row topic-manual'>";
                $rule = '~<img(.*?)src=\"(.*?)\"(.*?)>~';
                preg_match($rule, $value['content'], $img);
                if ($img) {
                    echo "<div class='col-md-4'><img src=" . $img[2] . " alt=" . $value['title'] . ">";
                } else {
                    echo "<div class='col-md-4'>" . Html::img('@web/img/default/manuals.jpg', ['alt' => $value['title']]);
                }

                echo "<h4>" . Html::a($value['title'], Url::toRoute($slug . '/download/' . $value['id'])) . "</h4>";
//                echo "<p>";
////                echo "<span class='glyphicon glyphicon-time' aria-hidden='true'></span>&nbsp;" . $date;
//                echo "&nbsp;&nbsp;&nbsp;&nbsp;<span class='glyphicon glyphicon-tag' aria-hidden='true'></span>&nbsp;";
//                foreach ($tag_arr as $tag) {
//                    echo Html::a(trim($tag), Url::toRoute('topic/' . trim($tag))) . "&nbsp;&nbsp;";
//                }
//                echo "</p><br />";
//                echo "<div class='post-index-content'>" . $value['description'] . "</div>";
                echo "</div></div>";
            }
        } else {
            echo "该模块下暂无内容！";
        }
//        echo LinkPager::widget(['pagination' => $pagination]);
        ?>
        <hr>
        <h3 class="yellow"><a href="/<?= $slug; ?>/posts"><i class="iconfont">&#xe604;</i>进阶 · 文档</a></h3>
        <?php
        if (!empty($posts)) {
            foreach ($posts as $value) {
                echo "<div class='row topic-post-img'>";
                $rule = '~<img(.*?)src=\"(.*?)\"(.*?)>~';
                $date = date("Y-m-d H:i:s", $value['created_at']);

                $tag_arr = explode(';', $value['tag']);

                preg_match($rule, $value['content'], $img);
                if ($img) {
                    echo "<div class='col-md-4'><img src=" . $img[2] . " alt=" . $value['title'] . "></div>";
                } else {
                    echo "<div class='col-md-4'><img src='" . Url::to('@web/img/', TRUE) . "default.jpg' alt=" . $value['title'] . "></div>";
                }
                echo "<div class='col-md-8'>";
                echo "<h4>" . Html::a($value['title'], Url::toRoute($slug . '/post/' . $value['id'])) . "</h4>";
                echo "<p><span class=' glyphicon glyphicon-eye-open' aria-hidden='true'></span>&nbsp;" . $value['views'] . "&nbsp;&nbsp;&nbsp;&nbsp;";
                echo "<span class='glyphicon glyphicon-time' aria-hidden='true'></span>&nbsp;" . $date . "&nbsp;&nbsp;&nbsp;&nbsp;";
                echo "&nbsp;&nbsp;&nbsp;&nbsp;<span class='glyphicon glyphicon-tag' aria-hidden='true'></span>&nbsp;";
                foreach ($tag_arr as $tag) {
                    echo Html::a($tag, Url::toRoute($slug . '/topic/' . $tag)) . "&nbsp;&nbsp;";
                }
                echo "</p><br />";
                echo "<P>" . $value['description'] . "</p></div>";
                echo "</div>";
                echo "<hr>";
            }
        } else {
            echo "该模块下暂无内容！";
        }
        ?>
        <h3 class="purple"><a href="/<?= $slug; ?>/videos"><i class="iconfont">&#xe603;</i>实战 · 视频</a></h3>
        <?php
        if (!empty($videos)) {
            foreach ($videos as $value) {
//                $date = date("Y-m-d H:i:s", $value['created_at']);
                echo "<div class='row topic-manual'>";
                $rule = '~<img(.*?)src=\"(.*?)\"(.*?)>~';
                preg_match($rule, $value['content'], $img);
                if ($img) {
                    echo "<div class='col-md-4'><img src=" . $img[2] . " alt=" . $value['title'] . ">";
                } else {
                    echo "<div class='col-md-4'>" . Html::img('@web/img/default/videos.jpg', ['alt' => $value['title']]);
                }

                echo "<h4>" . Html::a($value['title'], Url::toRoute($slug . '/video' . $value['vid'].'/'.$value['id'])) . "</h4>";
                echo "</div></div>";
            }
        } else {
            echo "该模块下暂无内容！";
        }
//        echo LinkPager::widget(['pagination' => $pagination]);
        ?>        
    </div>
    <div class="col-md-3">
        <div class="list-group mt30">
            <?php
            $category = common\components\CategoryHelper::category_widget($cid);
            foreach ($category as $value) {
                echo Html::a($value['title'], Url::toRoute($slug . '/post/topic-' . $value['id']), ['class' => 'list-group-item']);
            }
            ?>
        </div>
    </div>   
</div>
